//
//  WeatherForecastView.m
//  WeatherGuide
//
//  Created by lanou3g on 15/12/17.
//  Copyright © 2015年 李明. All rights reserved.
//

#import "WeatherForecastView.h"
#import "DailyForecast.h"
#import "WeathersCollectionViewCell.h"
@implementation WeatherForecastView


- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        self.layer.borderWidth = 1;
        [self allViews];
    }
    return self;
}

- (void)allViews
{
    
    self.dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 100, 50)];
    self.dateLabel.text = @"暂无";
    [self addSubview:self.dateLabel];
    
    self.weatherImageView = [[UIImageView alloc] initWithFrame:CGRectMake(120, 10, 40, 40)];
    self.weatherImageView.image = [UIImage imageNamed:@"999.png"];
    [self addSubview:self.weatherImageView];
    
    self.weatherLabel = [[UILabel alloc] initWithFrame:CGRectMake(180, 5, 90, 50)];
    self.weatherLabel.textAlignment = NSTextAlignmentCenter;
    self.weatherLabel.layer.borderColor = [[UIColor whiteColor] CGColor];
    self.weatherLabel.layer.borderWidth = 1;
    self.weatherLabel.text = @"暂无";
    [self addSubview:self.weatherLabel];
    
    self.temperatureLabel = [[UILabel alloc] initWithFrame:CGRectMake(270, 5, 85, 50)];
    self.temperatureLabel.textAlignment = NSTextAlignmentCenter;
    self.temperatureLabel.layer.borderWidth = 1;
    self.temperatureLabel.layer.borderColor = [[UIColor whiteColor] CGColor];
    self.temperatureLabel.text = @"暂无";
    [self addSubview:self.temperatureLabel];
}

- (void)setDailyForecast:(DailyForecast *)dailyForecast
{
   
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *date = [formatter dateFromString:dailyForecast.date];
    
    if ([date timeIntervalSinceNow] < 0) {
        self.dateLabel.text = @"今天";
    }else if ([date timeIntervalSinceNow] < 60 * 60 * 24){
        self.dateLabel.text = @"明天";
    }else{
        self.dateLabel.text = dailyForecast.date;
    }
    self.weatherLabel.text = dailyForecast.cond;
    
    self.temperatureLabel.text = [NSString stringWithFormat:@"%@°~%@°",dailyForecast.min,dailyForecast.max];
    self.weatherImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png",dailyForecast.code_n]];
//    NSLog(@"dailyForecast-----------%@",dailyForecast.code_d);
}

@end
